<extend name="Include:Layout"/>
<block name="title">绑定信息</block>
<block name="style">
<style>

</style>
</block>

<block name="main">
	<div class="weui_tab">
		<div class="weui_navbar">
			<div class="toolbar">
		        <div class="toolbar-inner">
		            <h1 class="title" id="banji_title">绑定信息</h1>
		        </div>
		    </div>
		</div>
		<div class="weui_tab_bd container" id="container">
			<div class="weui_cells weui_cells_form">
			   <div class="weui_cell weui_vcode">
			    <div class="weui_cell_hd"><label class="weui_label">手机号码</label></div>
			    <div class="weui_cell_bd weui_cell_primary">
			     	<input class="weui_input" type="number" id="mobile" pattern="[0-9]*" placeholder="请输入号码">
			    </div>
			    <div class="weui_cell_ft">
			      <a href="javascript:;" class="weui_btn weui_btn_primary" id="sendsms">发送</a>
			    </div>
			  </div>
			  <div class="weui_cell">
			    <div class="weui_cell_hd"><label class="weui_label">验证码</label></div>
			    <div class="weui_cell_bd weui_cell_primary">
			      <input class="weui_input" type="number" id="code" pattern="[0-9]*" placeholder="请输入验证码">
			    </div>
			  </div>
			  <div class="weui_cell">
			    <div class="weui_cell_hd"><label class="weui_label">真实姓名</label></div>
			    <div class="weui_cell_bd weui_cell_primary">
			      <input class="weui_input" type="text" name="realname" id="realname" placeholder="请输入您的真实姓名">
			    </div>
			  </div>
			</div>
		    <div class="weui_btn_area">
		    	<input type="hidden" name="uid" value="{$uid}"/>
		        <a class="weui_btn weui_btn_primary btn-submit">提交</a>
		    </div>
		</div>
	</div>
 
</block>

<block name="script">
<script>
$(".btn-submit").click(function(){
	var thisBtn = $(this);
	if(thisBtn.attr('disabled') == 'disabled') {
        return;
	}
	var mobile = $("#mobile").val();
	var code = $("#code").val();
	var realname = $("#realname").val();
	if(mobile == ''){
		$.toast("请输入手机号码","text");
		return false;
	}
	if(code == ''){
		$.toast("请输入验证码","text");
		return false;
	}
	if(realname == ''){
		$.toast("请输入真实姓名","text");
		return false;
	}
	var uid = $("input[name='uid']").val();
	thisBtn.attr('disabled', 'disabled');
	$.post('/home/user/dosave',{mobile:mobile,code:code,realname:realname,uid:uid},function(ret){
		thisBtn.removeAttr('disabled');
		if(ret.status){
			$.toast(ret.info,"text", function() {
				location.href= ret.url;
			});
		}else{
			$.alert(ret.info,"");
		}
	});
})
$("#sendsms").click(function(){
	if($(this).hasClass('weui_btn_disabled')){
		return false;
	}
	var mobile = $("#mobile").val();
	if(mobile == ''){
		$.toast("输入手机号码","text");
		return false;
	}
	$.post('/api/api/sendsms',{mobile:mobile,type:'bangding'},function(ret){
		if(ret.status){
			settime('sendsms',60);
			//$.toast("短信已发送","text");
		}else{
			$.toast("短信发送失败","text");
		}
	});
})
function settime(obj,time){
	if (time == 0) { 
		$("#"+obj).removeClass("weui_btn_disabled").text("发送");
		return;
	} else { 
		$("#"+obj).addClass('weui_btn_disabled').text(time); 
		time--; 
	} 
	setTimeout(function() { 
		settime(obj,time) 
	},1000) 
}
</script>
</block>